﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace nbb.darbo_grafikas
{    
    internal partial class FormChangeLineColors : Form
    {
        internal FormChangeLineColors()
        {
            InitializeComponent();
            // bla bla bla - užpildyti dgv iš duomenų bazės. Nustatyti stulpelių sąvybes (pločius);
            setDgvCellColors();
        }


        private void dgvDSColors_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            // keisti spalvą
            int rowindex = e.RowIndex;
            byte alpha = Convert.ToByte(dgv.Rows[rowindex].Cells["Spalva_A"].Value);
            byte red = Convert.ToByte(dgv.Rows[rowindex].Cells["Spalva_R"].Value);
            byte green = Convert.ToByte(dgv.Rows[rowindex].Cells["Spalva_G"].Value);
            byte blue = Convert.ToByte(dgv.Rows[rowindex].Cells["Spalva_B"].Value);
            ColorDialog cd = new ColorDialog();
            Color c = Color.FromArgb(alpha, red, green, blue);
            cd.Color = c;
            cd.AllowFullOpen = true;
            cd.ShowHelp = true;
            if (cd.ShowDialog() == DialogResult.OK)
            {
                c = cd.Color;
                dgv.Rows[rowindex].Cells["Spalva_A"].Value = c.A;
                dgv.Rows[rowindex].Cells["Spalva_R"].Value = c.R;
                dgv.Rows[rowindex].Cells["Spalva_G"].Value = c.G;
                dgv.Rows[rowindex].Cells["Spalva_B"].Value = c.B;
                foreach (DataGridViewCell cl in dgv.Rows[rowindex].Cells)
                    cl.Style.BackColor = c;
            }

        }

        private void setDgvCellColors()
        {
            Color c;
            byte alpha;
            byte red;
            byte green;
            byte blue;
            foreach (DataGridViewRow rw in dgv.Rows)
            {
                alpha = Convert.ToByte(rw.Cells["Spalva_A"].Value);
                red = Convert.ToByte(rw.Cells["Spalva_R"].Value);
                green = Convert.ToByte(rw.Cells["Spalva_G"].Value);
                blue = Convert.ToByte(rw.Cells["Spalva_B"].Value);
                c = Color.FromArgb(alpha, red, green, blue);
                foreach (DataGridViewCell cl in rw.Cells)
                {
                    if (cl.Visible) cl.Style.BackColor = c;
                }
            }

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            // išsaugoti duomenų bazėje naujas spalvas ir išeiti
        }
    }
}
